package com.deram.ctin.serv.search.solr.impl;

import com.deram.ctin.common.bean.PageResult;
import com.deram.ctin.common.utils.PasswordUtils;
import com.deram.ctin.serv.customs.entity.CustomsInfo;
import com.deram.ctin.serv.customs.entity.CustomsTrade;
import com.deram.ctin.serv.search.entity.solr.api.SolrCustomsInfoApi;
import com.deram.ctin.serv.search.entity.solr.bean.SolrCustomsInfo;
import com.deram.ctin.serv.search.entity.solr.search.WebCustomsSearchParam;
import com.deram.ctin.serv.search.solr.service.SolrCustomsInfoService;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.UUID;


@RestController
public class SolrCustomsInfoApiImpl implements SolrCustomsInfoApi {

    @Autowired
    private SolrCustomsInfoService solrCustomsInfoService;

    @Override
    public SolrCustomsInfo find(@RequestParam("id") Long id) {
        return solrCustomsInfoService.findById(id);
    }

    @Override
    public PageResult<SolrCustomsInfo> findByKeyWords(@RequestBody WebCustomsSearchParam keywords, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return solrCustomsInfoService.findByKeyWords(keywords,pageNo,pageSize);
    }

    @Override
    public List<SolrCustomsInfo> findAll() {
        return solrCustomsInfoService.findAll();
    }


    @Override
    public SolrCustomsInfo save(@RequestBody CustomsTrade param) {
        SolrCustomsInfo solrCustomsInfo = new SolrCustomsInfo();
        solrCustomsInfo.setId(param.getId());
        solrCustomsInfo.setVoyageNumber(param.getVoyageNumber());
        solrCustomsInfo.setUse(param.getUse());
        solrCustomsInfo.setTypeName(param.getTypeName());
        solrCustomsInfo.setType(param.getType());
        solrCustomsInfo.setTransportType(param.getTransportType());
        solrCustomsInfo.setTransportName(param.getTransportName());
        solrCustomsInfo.setTransitCountry(param.getTransitCountry());
        solrCustomsInfo.setTrafficUnit(param.getTrafficUnit());
        solrCustomsInfo.setTradeName(param.getTradeName());
        solrCustomsInfo.setTradeModel(param.getTradeModel());
        solrCustomsInfo.setTotalWeight(param.getTotalWeight().toString());
        solrCustomsInfo.setTotalGross(param.getTotalGross().toString());
        solrCustomsInfo.setTaxTreatment(param.getTaxTreatment());
        solrCustomsInfo.setTaxTreatmentName(param.getTaxTreatmentName());
        solrCustomsInfo.setSourceArea(param.getSourceArea());
        solrCustomsInfo.setShipsName(param.getShipsName());
        solrCustomsInfo.setRemarks(param.getRemarks());
        solrCustomsInfo.setPropertyName(param.getPropertyName());
        solrCustomsInfo.setProperty(param.getProperty());
        solrCustomsInfo.setOwnerUnit(param.getOwnerUnit());
        solrCustomsInfo.setShipsName(param.getShipsName());
        solrCustomsInfo.setApplicationUnit(param.getApplicationUnit());
        solrCustomsInfo.setKeywords(param.getKeywords());
        solrCustomsInfo.setBusinessUnit(param.getBusinessUnit());
        solrCustomsInfo.setCasesNumber(param.getCasesNumber());
        solrCustomsInfo.setCompetentCustoms(param.getCompetentCustoms());
        solrCustomsInfo.setContainerQuantity(param.getContainerQuantity());
        solrCustomsInfo.setLegalWeight(param.getLegalWeight().doubleValue());
        solrCustomsInfo.setHsCode(param.getHsCode());
        solrCustomsInfo.setHsModels(param.getHsModels());
        solrCustomsInfo.setHsName(param.getHsName());
        solrCustomsInfo.setHsNumber(param.getHsNumber());
        solrCustomsInfo.setGoodsNumber(param.getGoodsNumber());
        solrCustomsInfo.setEnterpriseRegistry(param.getEnterpriseRegistry());
        solrCustomsInfo.setExemptionNature(param.getExemptionNature());
        solrCustomsInfo.setExportCustoms(param.getExportCustoms());
        solrCustomsInfo.setExportDate(param.getExportDate());
        solrCustomsInfo.setDeclarationAmount(param.getDeclarationAmount().doubleValue());
        solrCustomsInfo.setDeclarationDate(param.getDeclarationDate());
        solrCustomsInfo.setDeclarationNumber(param.getDeclarationNumber());
        solrCustomsInfo.setDeclarationPrice(param.getDeclarationPrice().doubleValue());
        solrCustomsInfo.setDeliveryName(param.getDeliveryName());
        solrCustomsInfo.setDestinationCountry(param.getDestinationCountry());
        solrCustomsInfo.setDischargingPort(param.getDischargingPort());
        solrCustomsInfo.setDollarAmount(param.getDollarAmount().doubleValue());
        solrCustomsInfo.setDollarPrice(param.getDollarPrice().doubleValue());
        solrCustomsInfo.setContinentCode(param.getContinentCode());
        solrCustomsInfo.setContinentName(param.getContinentName());
        solrCustomsInfo.setCountryCode(param.getCountryCode());
        solrCustomsInfo.setCountryName(param.getCountryName());
        solrCustomsInfo.setEnterId(param.getEnterId());
        return solrCustomsInfoService.save(solrCustomsInfo);
    }

    @Override
    public void delete(@RequestParam("id") Long id) {
        solrCustomsInfoService.delete(id);
    }
}